import React, { Component, Fragment } from 'react';
import classNames from 'classnames';
import { connect } from 'dva';
import Bind from 'lodash-decorators/bind';
import PageHeaderWrapper from '@/components/PageHeaderWrapper';
import {
  Form,
  Input,
  DatePicker,
  Select,
  Button,
  Card,
  InputNumber,
  Radio,
  Icon,
  Tooltip,
} from 'antd';

const FormItem = Form.Item;
@Form.create()
@connect(({ category, loading }) => ({
  category,
  submitting: null,
}))
export default class Category extends Component{
	handleSubmit=e=>{
		e.preventDefault();
		this.props.form.validateFieldsAndScroll((err, values) => {
      	if (!err) {	
	        this.props.dispatch({
	          type: 'category/saveCategory',
	          payload: values,
	        });
      	}
    });
	}
	constructor(props,context){
		super(props,context);
	}
	render(){
		//this.props.location.search
		const { submitting } = this.props;
		const {getFieldDecorator } =this.props.form;
		const formItemLayout = {
	      labelCol: {
	        xs: { span: 24 },
	        sm: { span: 7 },
	      },
	      wrapperCol: {
	        xs: { span: 24 },
	        sm: { span: 12 },
	        md: { span: 10 },
	      },
    	};
    	  const submitFormLayout = {
		      wrapperCol: {
		        xs: { span: 24, offset: 0 },
		        sm: { span: 10, offset: 7 },
		      },
    		};
		return (
			 <PageHeaderWrapper title="创建分类">			 
			<Form onSubmit={this.handleSubmit} style={{marginTop:8}}>
			<FormItem  {...formItemLayout} label="分类编码">
				{getFieldDecorator('code', {
	                rules: [
	                  {
	                    required: true,
	                    message: '请输入分类编码',
	                  },
	                ],
	              })(<Input placeholder="请输入分类编码" />)}
			</FormItem>
			<FormItem  {...formItemLayout} label="分类名称">
				{getFieldDecorator('name', {
	                rules: [
	                  {
	                    required: true,
	                    message: '请输入分类名称',
	                  },
	                ],
	              })(<Input placeholder="请输入分类名称" />)}
			</FormItem>
			 <FormItem {...submitFormLayout} style={{ marginTop: 32 }}>
              <Button type="primary" htmlType="submit" loading={submitting}>
                提交
              </Button>
              <Button style={{ marginLeft: 8 }}>保存</Button>
              </FormItem>
			</Form>
			 </PageHeaderWrapper>
			);
	}
}
